//根据"男生"、"女生"获取书籍
import axios from "axios";
import { ElMessage } from "element-plus";
import { ref } from "vue";
import { getCurrentInstance } from "vue";

export async function getCommrnts(id) {
  console.log(id);
  const { proxy } = getCurrentInstance();
  try {
    const response = await proxy.$http.post("/api/comment/get", {
      type: "book",
      id: id,
    });
    const book = response.data.data.book;
    // console.log(book);
    const isSuccess = response.data.success;
    const message = response.data.message;
    // console.log(response.data);
    if (isSuccess === false) {
      ElMessage.error(message);
    } else {
      ElMessage.success("获取成功");
      return book;
    }
  } catch (error) {
    console.error(`Error fetching ${id} books:`, error);
    return [];
  }
}
